/**
    ATClab - scriptable Air Traffic Control simulations.
    Copyright (C) 2010 openatclab@gmail.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
**/

#ifndef __PACT_GLOBAL_HDR__
#define __PACT_GLOBAL_HDR__


#include <qobject.h>
#include <stdexcept>
#include <string>
#include "experiment.h"


namespace pact {

	/*!
	 *
	 */
	class Global : public QObject {
		Q_OBJECT
		friend struct GlobalFactory;
	private:
		Global( QObject *, const std::string &, int = 0 );
	public:
		~Global();
	public:
		const std::string& name() const { return _name; }
		int value() const { return _value; }
	signals:
		void value_changed(int x);

	public slots:
		void set_value( int x ) { _value = x; emit value_changed(x); }
	private:
		std::string _name;
		int			_value;
	};


	/*!
	 *
	 */
	struct GlobalFactory {
		static Global* create_variable( const Experiment *, const GlobalStateNode * );
	};


	/*!
	 * \struct atc::global_variable_error
	 */
	struct global_variable_error : public std::runtime_error {
		global_variable_error( const std::string &msg ) 
			:std::runtime_error( msg ) {}
	};


};


#endif
